package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.UserSecurityQuestion;
import com.ymttest.utils.YMTDateUtil;

public class UserSecurityQuestionWapper {
	SqlManager manage;

	public UserSecurityQuestionWapper() {
		manage = new SqlManager("UserSafe");
	}

	
	/**
	 * @param userId
	 * @return
	 */
	public List<UserSecurityQuestion> selectUsersecurityquestionByUserid(int userId) {
		List<UserSecurityQuestion> userSecurityQuestion = (List<UserSecurityQuestion>) manage.getSelectResults(
				"com.ymttest.database.mapping.UserSecurityQuestionMapper.selectUsersecurityquestionByUserid", userId);
		manage.commit();
		if(userSecurityQuestion!=null && userSecurityQuestion.size()>0){
			return userSecurityQuestion;
		}
		return null;
	}
	/**
	 * 查询双重认证
	 * @param userId
	 * @return
	 */
	public List<Map> selectUserdualsecurity(int userId) {
		Map m=new HashMap<>();
		m.put("uid", userId);
		List<Map> userSecurityQuestion = (List<Map>) manage.getSelectResults(
				"com.ymttest.database.mapping.UserSecurityQuestionMapper.selectUserdualsecurity", m);
		manage.commit();
		if(userSecurityQuestion!=null && userSecurityQuestion.size()>0){
			return userSecurityQuestion;
		}
		return null;
	}
	/**
	 * @param userId
	 * @return
	 */
	public int deleteVerifyLogByUserId(int userId) {
		int i =manage.delete(
				"com.ymttest.database.mapping.UserSecurityQuestionMapper.deleteVerifyLogByUserId", userId);
		manage.commit();
		return i;
	}
	public int deleteSellerOnlineStatus(int userid) {
		int i =manage.delete(
				"com.ymttest.database.mapping.UserSecurityQuestionMapper.deleteSellerOnlineStatus", userid);
		manage.commit();
		return i;
	}
	public int deleteUserdualsecurity(int userid) {
		int i =manage.delete(
				"com.ymttest.database.mapping.UserSecurityQuestionMapper.deleteUserdualsecurity", userid);
		manage.commit();
		return i;
	}
	public List<Map> selectSelleronlineStatus(int userId,String optype) {
		Map m=new HashMap<>();
		m.put("uid", userId);
		m.put("optype", optype);
		List<Map> userSecurityQuestion = (List<Map>) manage.getSelectResults(
				"com.ymttest.database.mapping.UserSecurityQuestionMapper.selectSelleronlineStatus", m);
		manage.commit();
		if(userSecurityQuestion!=null && userSecurityQuestion.size()>0){
			return userSecurityQuestion;
		}
		return null;
	}
	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
		manage = null;
	}

	public static void main(String[] args) {
//		UserSecurityQuestionWapper wapper = new UserSecurityQuestionWapper();
//		Logger.debug(wapper.selectSelleronlineStatus(3383, "10001"));
//		List<UserSecurityQuestion> list = wapper.selectUsersecurityquestionByUserid(2);
//		for (UserSecurityQuestion userSecurityQuestion : list) {
//			Logger.debug(userSecurityQuestion.getQuestionId());
//			Logger.debug(userSecurityQuestion.getQuestionAnswer());
//		}
	}
}
